package com.heihei.config;

import com.heihei.constant.MessageConstant;
import com.heihei.util.ConfigUtilF;

import java.util.Properties;

public class ConfigProperties {
    /** 合并制作视频预览图 图片张数： */
    public static Integer VIDEO_MERGE_IMG_COUNT;

    /** 视频预览相关 */
    /** 视频最大处理数 */
    public static Integer MAX_SYNC_HANDLE_VIDEO_COUNT;
    /** 单个视频的预览图数量 */
    public static Integer SINGLE_VIDEO_PREVIEW_IMG_COUNT;

    /** gclone相关 */
    public static String[] DRIVE_NAME_ARR;
    public static String SEPARATOR;
    public static String PRE_FILENAME;
    public static String ZHUAN_CUN_DES;
    public static String ZHUAN_CUN_DRIVE;

    /** html预览相关 */
    public static Integer HTML_IMG_COUNT;

    /** 压缩相关 */
    /** 压缩密码 */
    public static String COM_PASSWORD;
    /** 是否开启分卷压缩 */
    public static Boolean DIVIDE_FLAG;
    /** 分卷大小 */
    public static String SECTION_SIZE;
    /** 压缩文件格式 */
    public static String ZIP_STYLE;

    /** 解压相关 */
    public static String ZIP_PATH;
    public static String SCRIPT_PATH;

    /** 图片预览相关 */
    /** 图片规格，宽高比的最大、最小值 */
    public static Double MIN_WIDTH_DIVIDE_HEIGHT;
    public static Double MAX_WIDTH_DIVIDE_HEIGHT;
    /** 横向图片宽度 */
    public static Integer ACCROSS_IMG_WIDTH;
    /** 纵向图片宽度 */
    public static Integer VERTICAL_IMG_WIDTH;
    /** 横向图片每行最大数量 */
    public static Integer ACCROSS_IMG_LINE_MAX_COUNT;
    /** 纵向图片每行最大数量 */
    public static Integer VERTICAL_IMG_LINE_MAX_COUNT;
    /** 图片与图片之间的间隔 */
    public static Integer IMG_INTERVAL;
    /** 间隔（横款图的左右间隔） */
    public static Integer ACCROSS_IMG_HORIZONTAL_INTERVAL;
    /** 样本图片数 */
    public static Integer SAMPLE_IMG_COUNT;
    /** 背景色  RGB */
    public static Integer RED;
    public static Integer GREEN;
    public static Integer BLUE;
    /** 生成图片的格式 */
    public static String GENERATE_IMG_STYLE;
    /** 生成预览图的后缀 */
    public static String GENERATE_IMG_SUFFIX;
    /** 分隔预览 横向图片每张最大个数 */
    public static Integer ACCROSS_LINE_EVERY_IMG;
    /** 分隔预览 纵向图片每张最大个数 */
    public static Integer VERTICAL_LINE_EVERY_IMG;
    /** 最少图片处理张数 */
    public static Integer MIN_IMG_HANDLE_COUNT;

    //图片轻量化相关（图片轻量化的宽度）
    public static Integer REDUCE_ACCROSS_IMG_WIDTH;
    public static Integer REDUCE_VERTICAL_IMG_WIDTH;

    //ffmpeg地址
    public static String FFMPEG_HOME_DIR;

    //缩略图相关
    //缩略图宽度
    public static Integer THUMB_WIDHT;


    static {
        init();
    }

    private static void init() {
        Properties properties = ConfigUtilF.getProperties();
        //视频合并相关
        Integer integer = Integer.valueOf(properties.getProperty("videoMergePreview.mergeImgCount"));
        VIDEO_MERGE_IMG_COUNT = integer;

        //图片预览相关
        MAX_SYNC_HANDLE_VIDEO_COUNT = Integer.valueOf(properties.getProperty("videoPreview.maxSyncHandleCount"));
        SINGLE_VIDEO_PREVIEW_IMG_COUNT = Integer.valueOf(properties.getProperty("videoPreview.singleVideoPreviewImgCount"));

        //gclone相关
        DRIVE_NAME_ARR = properties.getProperty("gclone.driveName").split(",");
        SEPARATOR = properties.getProperty("gclone.separator");
        PRE_FILENAME = properties.getProperty("gclone.preFileName");
        ZHUAN_CUN_DES = properties.getProperty("gclone.zhuanCunDes");
        ZHUAN_CUN_DRIVE = properties.getProperty("gclone.zhuanCunDrive");

        //html预览相关
        HTML_IMG_COUNT = Integer.valueOf(properties.getProperty("imgHtml.sampleImgCount"));

        //压缩密码
        try{
            COM_PASSWORD = properties.getProperty("comPress.password").trim();
        } catch (NullPointerException e) {
            COM_PASSWORD = null;
        }
        //是否开启分卷
        DIVIDE_FLAG = Boolean.valueOf(properties.getProperty("comPress.divideFlag"));
        //分卷大小
        SECTION_SIZE = properties.getProperty("comPress.sectionSize").trim();
        ZIP_STYLE = properties.getProperty("comPress.zipStyle").trim();

        //解压相关
        SCRIPT_PATH = properties.getProperty("depress.scriptPath");
        ZIP_PATH = properties.getProperty("depress.zipPath");

        //图片预览相关
        MIN_WIDTH_DIVIDE_HEIGHT = Double.valueOf(properties.getProperty("imgPreview.minWidthDivideHeight"));
        MAX_WIDTH_DIVIDE_HEIGHT = Double.valueOf(properties.getProperty("imgPreview.maxWidthDivideHeight"));
        ACCROSS_IMG_WIDTH = Integer.valueOf(properties.getProperty("imgPreview.accrossImgWidth"));
        VERTICAL_IMG_WIDTH = Integer.valueOf(properties.getProperty("imgPreview.verticalImgWidth"));
        ACCROSS_IMG_LINE_MAX_COUNT = Integer.valueOf(properties.getProperty("imgPreview.accrossLineCount"));
        VERTICAL_IMG_LINE_MAX_COUNT = Integer.valueOf(properties.getProperty("imgPreview.verticalLineCount"));
        IMG_INTERVAL = Integer.valueOf(properties.getProperty("imgPreview.imgInterval"));
        ACCROSS_IMG_HORIZONTAL_INTERVAL = new Double(1D * IMG_INTERVAL * (VERTICAL_IMG_LINE_MAX_COUNT + 1) / (ACCROSS_IMG_LINE_MAX_COUNT + 1)).intValue();
        SAMPLE_IMG_COUNT = Integer.valueOf(properties.getProperty("imgPreview.sampleImgCount"));
        String[] split = properties.getProperty("imgPreview.backgroundColor").split(",");
        RED = Integer.valueOf(split[0]);
        GREEN = Integer.valueOf(split[1]);
        BLUE = Integer.valueOf(split[2]);
        GENERATE_IMG_STYLE = properties.getProperty("imgPreview.generateImgStyle");
        GENERATE_IMG_SUFFIX = properties.getProperty("imgPreview.generateImgSuffix");
        MIN_IMG_HANDLE_COUNT = Integer.valueOf(properties.getProperty("imgPreview.minImgHandleCount"));

        // 分割图片预览相关
        VERTICAL_LINE_EVERY_IMG = Integer.valueOf(properties.getProperty("divideImgPreview.verticalLineEveryImg"));
        ACCROSS_LINE_EVERY_IMG = Integer.valueOf(properties.getProperty("divideImgPreview.accrossLineEveryImg"));

        //图片轻量化相关
        REDUCE_ACCROSS_IMG_WIDTH = Integer.valueOf(properties.getProperty("reduceImg.accrossImgWidth"));
        REDUCE_VERTICAL_IMG_WIDTH = Integer.valueOf(properties.getProperty("reduceImg.verticalImgWidth"));

        //ffmpeg地址
        FFMPEG_HOME_DIR = properties.getProperty("ffmpeg.home-dir");

        //缩略图宽度
        THUMB_WIDHT = Integer.valueOf(properties.getProperty("thumb.width"));
    }

    /**
     * 方法描述: 更新配置属性
     *
     * @param
     * @Return {@link boolean}
     * @throws
     * @author duanhengfei
     * @date 2021年02月14日 10:10:39
     */
    public static boolean updateProperties(){
        try {
            ConfigUtilF.init();
            ConfigProperties.init();
            System.out.println("配置属性已刷新");
            return true;
        } catch (Exception e) {
            System.out.println(MessageConstant.ERROR_MESSAGE + " 配置属性更新失败！！！ 请检查配置文件是否合法");
            return false;
        }
    }

    public ConfigProperties() {
    }
}